--[[
    函数：lua3_lab_del_design
    功能：删除模版
    参数：ARGV[1]:design_id，模版id，
    返回：0表示成功，1表示失败
--]]

-- ########################################################

-- 分类的前缀
local PREFIX_TYPE = "lab_type_"
-- 标签的前缀
local PREFIX_LABEL_INDUSTRY = "lab_label_industry_"
local PREFIX_LABEL_SCENE = "lab_label_scene_"
local PREFIX_LABEL_STYLE = "lab_label_style_"
local PREFIX_LABEL_COLOR = "lab_label_color_"
local PREFIX_LABEL_CUSTOM = "lab_label_custom_"

-- 排序的key
local KEY_SORT = "lab_sort"
-- ID-模版缓存的前缀
local PREFIX_DESIGN = "lab_d_"

-- key的连接符号
local PREFIX_S = "*"
-- 数组字符串的分割符号
local PREFIX_ARRAY_SPLIT = ","

-- ########################################################
-- 将数据从集合中删除
local removeFromSet = function(prefix,prefix_s,design_id)
    local key = prefix..prefix_s
    local l_keys = redis.call('keys',key)
    local r_len = #l_keys
    if(r_len>0)
    then
        for i= 1, r_len do
            local key = prefix..l_keys[i]
            redis.call('srem',key, design_id)
        end
    end

end

-- ########################################################
-- “行业标签－模版缓存”集合 D2
removeFromSet( PREFIX_LABEL_INDUSTRY, PREFIX_S, design_id)
-- “场景标签－模版缓存”集合 D3
removeFromSet(PREFIX_LABEL_SCENE, PREFIX_S,design_id)
-- “颜色标签－模版缓存”集合 D4
removeFromSet( PREFIX_LABEL_COLOR, PREFIX_S,design_id)
-- “风格标签－模版缓存”集合 D5
removeFromSet( PREFIX_LABEL_STYLE, PREFIX_S,design_id)
-- “自定义标签－模版缓存”集合 D6
removeFromSet( PREFIX_LABEL_CUSTOM, PREFIX_S,design_id)



-- ########################################################
-- "id－模版缓存”hash表  D7
local key7 = PREFIX_DESIGN..design_id
redis.call('hdel',key7, 'search_result')

-- ########################################################
-- “模版－排序字段”有序集合  D8
local key8 = KEY_SORT
redis.call('zrem',key8, design_id)

-- ########################################################
return 0